package com.glsc.ngateway.platform.controller.webfield;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.webfield.FlowFormWebField;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.webfield.TableFormWebField;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.platform.service.webfield.FlowFormWebFieldService;
import com.glsc.ngateway.platform.service.webfield.TableFormWebFieldService;
import com.glsc.ngateway.platform.utils.SpringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhengyr
 * @date 2024/2/2-10:18
 */
@RestController
@RequestMapping("/api/webFieldConfig/")
@Api(value = "前端页面配置管理", tags = {"前端页面配置管理"})
public class WebFieldController {

    @Resource
    FlowFormWebFieldService flowWebFieldService;
    
    @Resource
    TableFormWebFieldService tableFieldService;

    @GetMapping("/flowFormField/listPage")
    @ApiOperation(value = "流程类页面配置分页", notes = "流程类页面配置分页")
    public PlatformResponse<Page<FlowFormWebField>> flowFormWebFieldListpage(@ApiParam(value = "流程名称") @RequestParam(required = false) String flowName,
                                                                             @ApiParam(value = "页码从1开始") @RequestParam(required = false) Integer pageNo,
                                                                             @ApiParam(value = "每页显示条数 默认10") @RequestParam(required = false) Integer pageSize) {
        Page<FlowFormWebField> page = flowWebFieldService.queryFlowFormWebFieldPage(pageNo, pageSize, flowName);
        return PlatformResponse.successData(page);
    }

    @GetMapping("/flowFormField/findById")
    @ApiOperation(value = "根据id查询流程类页面配置", notes = "根据id查询流程类页面配置")
    public PlatformResponse<FlowFormWebField> findFlowFormWebFieldById(@ApiParam(value = "id") @RequestParam(required = true) Integer id) {
        if (!SpringUtil.isTestingByActiveProfile()){
            return PlatformResponse.failedMsg("只允许开发环境访问！");
        }
        FlowFormWebField data = flowWebFieldService.queryFlowFormWebFieldById(id);
        return PlatformResponse.successData(data);
    }

    @PostMapping("/flowFormField/addOrUpdate")
    @ApiOperation(value = "添加修改流程类页面配置", notes = "添加修改流程类页面配置")
    public PlatformResponse<String> addOrUpdateFlowFormWebField(@RequestBody FlowFormWebField params) {
        String ident = flowWebFieldService.addOrUpdateFlowFormWebField(params);
        return PlatformResponse.successData(ident);
    }

    @PostMapping("/flowFormField/delete")
    @ApiOperation(value = "删除流程类页面配置", notes = "删除流程类页面配置")
    public PlatformResponse<Void> deleteFlowFormWebField(@RequestBody FlowFormWebField param) {
        flowWebFieldService.deleteFlowFormWebField(param);
        return PlatformResponse.successMsg("删除成功！");
    }

    /**
     *
     * 以下是列表表单的controller接口
     */

    @GetMapping("/tableFormField/listPage")
    @ApiOperation(value = "流程类页面配置分页", notes = "流程类页面配置分页")
    public PlatformResponse<Page<TableFormWebField>> tableFormWebFieldListpage(@ApiParam(value = "页面名称") @RequestParam(required = false) String pageName,
                                                   @ApiParam(value = "页码从1开始") @RequestParam(required = false) Integer pageNo,
                                                   @ApiParam(value = "每页显示条数 默认10") @RequestParam(required = false) Integer pageSize) {
        Page<TableFormWebField> page = tableFieldService.queryTableFormWebFieldPage(pageNo, pageSize, pageName);
        return PlatformResponse.successData(page);
    }

    @GetMapping("/tableFormField/findById")
    @ApiOperation(value = "根据id查询流程类页面配置", notes = "根据id查询流程类页面配置")
    public PlatformResponse<TableFormWebField> findTableFormWebFieldById(@ApiParam(value = "id") @RequestParam(required = true) Integer id) {
        if (!SpringUtil.isTestingByActiveProfile()){
            return PlatformResponse.failedMsg("只允许开发环境访问！");
        }
        TableFormWebField data = tableFieldService.queryTableFormWebFieldById(id);
        return PlatformResponse.successData(data);
    }

    @PostMapping("/tableFormField/addOrUpdate")
    @ApiOperation(value = "添加修改流程类页面配置", notes = "添加修改流程类页面配置")
    public PlatformResponse<String> addOrUpdateTableFormWebField(@RequestBody TableFormWebField params) {
        String ident = tableFieldService.addOrUpdateTableFormWebField(params);
        return PlatformResponse.successData(ident);
    }

    @PostMapping("/tableFormField/delete")
    @ApiOperation(value = "删除流程类页面配置", notes = "删除流程类页面配置")
    public PlatformResponse<Void> deleteTableFormWebField(@RequestBody TableFormWebField param) {
        tableFieldService.deleteTableFormWebField(param);
        return PlatformResponse.successMsg("删除成功！");
    }

}
